/**
  ******************************************************************************
  * @file    iic.c
  * @brief   This file provides code for the configuration
  *          of the IIC instances.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2023 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* Includes ------------------------------------------------------------------*/
#include "iic.h"

/* Defines -------------------------------------------------------------------*/

/* Variables -----------------------------------------------------------------*/
I2C_HandleTypeDef hi2c[IIC_NUM] = {
    {  .Instance = I2C1,
  .Init.ClockSpeed = 100000,
  .Init.DutyCycle = I2C_DUTYCYCLE_2,
  .Init.OwnAddress1 = 0,
  .Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT,
  .Init.DualAddressMode = I2C_DUALADDRESS_DISABLE,
  .Init.OwnAddress2 = 0,
  .Init.GeneralCallMode = I2C_GENERALCALL_DISABLE,
  .Init.NoStretchMode = I2C_NOSTRETCH_DISABLE},
    {  .Instance = I2C2,
  .Init.ClockSpeed = 100000,
  .Init.DutyCycle = I2C_DUTYCYCLE_2,
  .Init.OwnAddress1 = 0,
  .Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT,
  .Init.DualAddressMode = I2C_DUALADDRESS_DISABLE,
  .Init.OwnAddress2 = 0,
  .Init.GeneralCallMode = I2C_GENERALCALL_DISABLE,
  .Init.NoStretchMode = I2C_NOSTRETCH_DISABLE},
   {  .Instance = I2C3,
  .Init.ClockSpeed = 100000,
  .Init.DutyCycle = I2C_DUTYCYCLE_2,
  .Init.OwnAddress1 = 0,
  .Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT,
  .Init.DualAddressMode = I2C_DUALADDRESS_DISABLE,
  .Init.OwnAddress2 = 0,
  .Init.GeneralCallMode = I2C_GENERALCALL_DISABLE,
  .Init.NoStretchMode = I2C_NOSTRETCH_DISABLE}
};

/* Prototypes ----------------------------------------------------------------*/
void IicInit(void)
{
    __HAL_RCC_I2C1_CLK_ENABLE();
    if (HAL_I2C_Init(&hi2c[0]) != HAL_OK)
    {
        Error_Handler();
    }
    if (HAL_I2C_Init(&hi2c[1]) != HAL_OK)
    {
        Error_Handler();
    }
    if (HAL_I2C_Init(&hi2c[2]) != HAL_OK)
    {
        Error_Handler();
    }
}

